package com.hilaver.dzmis.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hilaver.dzmis.Constants;
import com.hilaver.dzmis.accesscontrol.AcUser;
import com.hilaver.dzmis.service.impl.CtServiceImpl;

/**
 * Servlet implementation class for Servlet: CodeTableServlet
 *
 */
 public class CodeTableServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public CodeTableServlet() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		CtServiceImpl ctService = new CtServiceImpl();
		PrintWriter writer = response.getWriter();
		Locale locale = (Locale)request.getSession().getAttribute(Constants.SESSION_LOCALE);
		Object user = request.getSession().getAttribute(Constants.SESSION_USER);
		if(user != null){
			ctService.setAcUser((AcUser)user);
		}
		try {
			writer.print(ctService.getAll(CtServiceImpl.PACKAGE_NAME + "." +name, locale));
		} catch (Exception e) {
			writer.print(e.getMessage());
			e.printStackTrace();
		}
		
		writer.close();
	}   	  	    
}